package com.test;

import org.apache.zookeeper.*;

import java.io.IOException;

/**
 * Created by jl on 2016/11/4.
 */
public class Demo {
    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {
        //使用集群的话就配置多台zookeeper地址
        ZooKeeper zk = new ZooKeeper("172.168.1.122:41802", 2000, new Watcher() {
            public void process(WatchedEvent watchedEvent) {
                System.out.println("触发了" + watchedEvent.getType() + "事件");
                System.out.println(watchedEvent.getState().toString());
            }
        });
        zk.create("/jl", "hello1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.setData("/jl", "hello2".getBytes(), 0);
        zk.delete("/jl", 1);
    }
}
